<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>前端监控</title>
</head>

<body>
  <div id="container">
    <div class="content">
      <input type="button" value="点击抛出错误1111221" onclick="errorClick()" />
      <input type="button" value="点击抛出promise错误" onclick="promisrErrorClick()" />
      <input id="successBtn" type="button" value="ajax成功请求" onclick="sendSuccess()" />
      <input id="errorBtn" type="button" value="ajax失败请求" onclick="sendError()" />
    </div>
  </div>
  <script>
    function errorClick() {
      window.someVar.error = "error";
    }
    function promisrErrorClick() {
      new Promise((resolve, reject) => {
        window.someVar.error = "error";
        // reject('error')
      }).then((res) => {
        console.log(2222, res);
      });
    }
    function sendSuccess() {
      let xhr = new XMLHttpRequest();
      xhr.open("GET", "/success", true);
      xhr.responseType = "json";
      xhr.onload = () => {
        console.log("success", xhr.response);
      };
      xhr.onerror = function (error) {
        console.log("error", error);
      };
      xhr.send();
    }
    function sendError() {
      let xhr = new XMLHttpRequest();
      xhr.open("POST", "/error", true);
      xhr.responseType = "json";
      xhr.onload = () => {
        console.log("success", xhr.response);
      };
      xhr.onerror = function (error) {
        console.log("error", error);
      };
      xhr.send("name=leerick");
    }
  </script>
</body>

</html>